package com.sea.base.pop

import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.sea.base.ui.IUIContext
import com.sea.base.utils.ViewBindingHelper

abstract class BaseViewBindingPopupWindow<T : ViewBinding>(ui: IUIContext) :
    BasePopupWindow(ui) {

    companion object {
        /**
         * 在mvvm里，一般的pop就是普通的v层，所以降级到activity里去
         */
        inline fun <T : ViewBinding> create(ui: IUIContext, crossinline onDialogCreate: BaseViewBindingPopupWindow<T>.() -> Unit) =
            BasePopupWindow.create(ui, onDialogCreate)
    }

    private var _vb: T? = null
    val vb: T
        get() {
            if (_vb == null) {
                preCreateRootView()
            }
            return _vb!!
        }

    override fun createRootView(inflateLayout: ViewGroup): View {
        _vb = ViewBindingHelper.getViewBindingInstance(
            this,
            layoutInflater,
            inflateLayout,
            false
        )
        return vb.root
    }
}